package com.guet.controller.teacher;

import com.guet.DTO.ManagementPageDTO;
import com.guet.DTO.ManagementStatusDTO;
import com.guet.result.PageResult;
import com.guet.result.Result;
import com.guet.service.ManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher/management")
@Slf4j
@CrossOrigin
public class ManagementController {
    @Autowired
    private ManagementService managementService;

    @PostMapping("list")
    public Result<PageResult> getManagementList(@RequestBody ManagementPageDTO managementPageDTO) {
        log.info("分页查询参数：{}", managementPageDTO);
        PageResult result = managementService.list(managementPageDTO);
        return Result.success(result);
    }

    /**
     * 更改学生账号的状态
     * @param managementStatusDTO
     * @return
     */
    @PutMapping("status")
    public Result<Object> updateStatus(@RequestBody ManagementStatusDTO managementStatusDTO){
        Integer id = managementStatusDTO.getId();
        String status = managementStatusDTO.getStatus();
        log.info("id:{},status:{}", id, status);
        managementService.updateStatus(id, status);
        return Result.success();
    }

    @PutMapping("password/{id}")
    public Result<Object> updatePassword(@PathVariable String id){
        log.info("id:{}", id);
        managementService.updatePassword(Integer.valueOf(id));
        return Result.success();
    }
}
